package net.sxnic.workflow.node.taglib;

import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.jstl.core.ConditionalTagSupport;

import net.sxnic.workflow.WorkflowConstants;

import org.apache.commons.lang3.StringUtils;

/**
 * 判断 nodes中是否包含当前节点currNode
 * @author yfsun
 *
 */
public class NodeSelectTag extends ConditionalTagSupport {

	private static final long serialVersionUID = -2428590164839198353L;

	private String currNode;

	// 流程名
	private String processName;

	// 通常情况 根据给定的节点别名来判断是否包含给出的节点 如果其中包含！则表示不包含
	private String nodes;

	@Override
	protected boolean condition() throws JspTagException {

		String nodeNames = "";
		boolean containsT = false;

		if (nodes.contains("!")) {
			containsT = true;
		}

		if (StringUtils.contains(nodes, ",")) {
			String[] node_s = StringUtils.split(nodes, ",");
			for (String n : node_s) {
				nodeNames = nodeNames
						+ ","
						+ WorkflowConstants.WF_NODENAME_MAP.get(processName)
								.get(n);
			}			
		} else {
			nodeNames = WorkflowConstants.WF_NODENAME_MAP.get(processName).get(
					nodes);
		}

		if (!containsT) {
			if (StringUtils.contains(nodeNames, currNode)) {
				return true;
			} else {
				return false;
			}
		} else {
			if (StringUtils.contains(nodeNames, currNode)) {
				return false;
			} else {
				return true;
			}
		}

	}

	public String getNodes() {
		return nodes;
	}

	public void setNodes(String nodes) {
		this.nodes = nodes;
	}

	public String getProcessName() {
		return processName;
	}

	public void setProcessName(String processName) {
		this.processName = processName;
	}

	public String getCurrNode() {
		return currNode;
	}

	public void setCurrNode(String currNode) {
		this.currNode = currNode;
	}

}
